/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio;

import aiaudio.lastfm.hbase.DatabaseConnector;
import aiaudio.database.DatabaseStorage;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;

/**
 *
 * @author nastya
 */
public class Application {

    private Configuration hadoop;
    private DatabaseStorage storage;
    private HBaseAdmin database;
    private String databaseName;

    private Application(String databaseName) throws MasterNotRunningException, ZooKeeperConnectionException {
        this.databaseName = databaseName;
        hadoop = DatabaseConnector.connect();
        database = new HBaseAdmin(hadoop);
        storage = new DatabaseStorage(hadoop, database, databaseName);
    }
    private static Application instance;

    public static void init(String databaseName) throws MasterNotRunningException, ZooKeeperConnectionException {
        instance = new Application(databaseName);
    }

    public DatabaseStorage getDatabaseStorage() {
        return storage;
    }

    public static DatabaseStorage database() {
        return instance.getDatabaseStorage();
    }
}
